﻿using System;
using com.eforceglobal.crux.configuration;
using com.eforceglobal.crux.configuration.FeatureManager;
using com.eforceglobal.crux.views.Administration;
using com.eforceglobal.crux.security;
using com.eforceglobal.crux.BusinessFacades;
using com.eforceglobal.crux.DTOs;

namespace com.eforceglobal.crux.controllers.Administration
{
    public class DefaultAdministrationController
    {
        IDefaultAdministration _view = null;
        public DefaultAdministrationController(IDefaultAdministration view)
        {
            _view = view;
        }

        public void InitView(bool IsPostBack)
        {
            ICruxSecurityManager cruxSecurityManager = CruxSecurityManagerFactory.GetSecurityManager();
            UserFacade userFacade = new UserFacade();
            UserInformation userInformation = cruxSecurityManager.GetUser(_view.UserID);
            IFeatureManager featureManager = FeatureManagerFactory.GetFeatureManager();

            bool isUserSuperAdmin = cruxSecurityManager.IsUserSuperAdministrator(userInformation);
            _view.ShowManageAllCompanies = isUserSuperAdmin;
            _view.ShowCompaniesToUsers = isUserSuperAdmin;
            _view.ShowManageMyCompany = cruxSecurityManager.IsUserAdministrator(userInformation);
            _view.ShowResetMyPassword = featureManager.IsFeatureSupported("ResetMyPassword");
            _view.ShowManageRoles = (isUserSuperAdmin && featureManager.IsFeatureSupported("ManageRoles"));
            _view.ShowEmalNotification = featureManager.IsFeatureSupported("EmailNotifications");
        }


        public void OpenManageCompanies()
        {
            NavigationController.OpenView("ManageCompanies");
        }

        public void OpenManageMyCompany(int CompanyID)
        {
            SessionData sessionData = new SessionData();
            UserInformation currentUser = (UserInformation) sessionData.CurrentUser;
            NavigationController.OpenView("ManageCompany", CompanyID);
        }

        public void OpenResetMyPassword()
        {
            SessionData sessionData = new SessionData();
            UserInformation currentUser = (UserInformation)sessionData.CurrentUser;
            NavigationController.OpenView("ResetPassword", currentUser.UserID);
        }
       
        public void OpenManageRoles()
        {
            NavigationController.OpenView("ManageRoles");
        }

        public void AssignUsersToCompanies()
        {
            NavigationController.OpenView("AssignCompaniesToUser");
        }

        public void OpenEmailNotification()
        {
            NavigationController.OpenView("EmailNotification");
        }
    }
}
